package cn.wanho.controller.manager;

import cn.wanho.dao.CmsPlaceMapper;
import cn.wanho.dto.CmsClassStage;
import cn.wanho.dto.CmsClassStudent;
import cn.wanho.dto.CmsUserGroup;
import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.service.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * @author huyu
 */
@RestController
@RequestMapping("/manager")
public class ManagerController {
    @Resource
    private CmsUserService cmsUserService;
    @Resource
    private CmsUserGroupService cmsUserGroupService;
    @Resource
    private CmsClassService cmsClassService;
    @Resource
    private CmsStageService cmsStageService;
    @Resource
    private CmsClassStageService cmsClassStageService;
    @Resource
    private CmsClassStudentService cmsClassStudentService;
    @Resource
    private CmsPlaceService cmsPlaceService;
    @Resource
    private CmsAuthorityService cmsAuthorityService;

    /**
     * 用户创建
     *
     * @param userName
     * @param placeId
     * @return
     */
    @PostMapping("/createUser")
    public ResultVO addUser(String userName, Integer placeId) {

        return cmsUserService.addUser(userName, placeId);
    }

    /**
     * 测试
     *
     * @return
     */
    @GetMapping("/first")
    public String addUser() {
        //cmsUserService.addUser(userName,placeId);
        return "success";
    }

    /**
     * 权限绑定
     *
     * @param cmsUserGroup
     * @return
     */
    @PostMapping("/addUserGroup")
    public ResultVO addUserGroup(CmsUserGroup cmsUserGroup) {
        return cmsUserGroupService.addUserGroup(cmsUserGroup);
    }

    /**
     * 创建班级
     *
     * @return
     */
    @PostMapping("/createClass")
    public ResultVO createClass(String className) {
        return cmsClassService.addClass(className);
    }

    /**
     * 创建阶段
     *
     * @param stageName
     * @return
     */
    @PostMapping("/createStage")
    public ResultVO createStage(String stageName) {
        System.out.println(stageName);
        return cmsStageService.addStage(stageName);
    }

    /**
     * 查看所有学生成绩（不判断是否授课完结）
     */
    @GetMapping("/selectStudentGrade")
    public ResultVO selectStudentGrade(@RequestParam(value = "classId", required = false) Integer classId,
                                       @RequestParam(value = "stageId", required = false) Integer stageId,
                                       @RequestParam(value = "teacherId", required = false) Integer teacherId,
                                       @RequestParam(value = "studentName", required = false) String studentName,
                                       @RequestParam(value = "stageNum", required = false) Integer stageNum
//                                       ,@RequestParam(value = "pageNum") Integer pageNum,
//                                       @RequestParam(value = "rowNum") Integer rowNum
    ) throws ParseException {
        return cmsUserService.selectStudentGrade(classId, stageId, teacherId, studentName, stageNum);
    }

    /**
     * 查看授课完结的学生成绩
     */


    /**
     * 阶段时间老师绑定
     *
     * @param cmsClassStage
     * @return
     */
    @PostMapping("/setStageTime")
    public ResultVO setStageTime(CmsClassStage cmsClassStage) {
        System.out.println(cmsClassStage);
        return cmsClassStageService.setClassStage(cmsClassStage);
    }

    /**
     * 学生班级绑定
     *
     * @param cmsClassStudent
     * @return
     */
    @PostMapping("/setStudentClass")
    public ResultVO setStudentClass(CmsClassStudent cmsClassStudent) {
        cmsClassStudentService.setStudentClass(cmsClassStudent);
        return null;
    }

    /**
     * 查询所有老师(信息 阶段 班级  是否在任)
     *
     * @param pageNum
     * @param rowsNum
     * @return
     */
    @GetMapping("/selectAllTeacher")
    public ResultVO selectAllTeacher(Integer pageNum, Integer rowsNum) {
        return cmsUserService.selectAllTeacher(pageNum, rowsNum);
    }

    /**
     * 添加教学点
     *
     * @param placeName
     * @return
     */
    @PostMapping("/addPlace")
    public ResultVO addPlace(String placeName) {
        return cmsPlaceService.addPlace(placeName);
    }

    /**
     * 移除教学点
     *
     * @param placeId
     * @return
     */
    @PostMapping("/deletePlace")
    public ResultVO deletePlace(Integer placeId) {
        return cmsPlaceService.deletePlace(placeId);
    }

    /**
     * 移除老师（老师离职）
     *
     * @param userId
     * @return
     */
    @PostMapping("/removeTeacher")
    public ResultVO removeTeacher(Integer userId) {
        return cmsUserService.removeTeacher(userId);
    }

    /**
     * 查询没有班级的学生
     *
     * @param pageNum
     * @param rowsNum
     * @return
     */
    @GetMapping("/selectAllStudent")
    public ResultVO selectAllStudent(Integer pageNum, Integer rowsNum) {
        return cmsUserService.selectAllStudent(pageNum, rowsNum);
    }

    /**
     * 获取班级
     *
     * @return
     */
    @GetMapping("/selectAllClass")
    public ResultVO selectAllClass() {
        return cmsClassService.selectAllClass();
    }

    /**
     * 获取老师列表
     *
     * @return
     */
    @GetMapping("/getTeacherList")
    public ResultVO getTeacherList() {
        return cmsUserService.selectAllTeacher2();
    }

    /**
     * 获取阶段表
     *
     * @return
     */
    @GetMapping("/getStageList")
    public ResultVO getStageList() {
        return cmsStageService.getStageList();
    }

    /**
     * 获取教学点列表
     * @return
     */
    @GetMapping("/getPlaceList")
    public ResultVO getPlaceList() {
        return cmsPlaceService.getPlaceList();
    }

    /**
     * 获取权限列表
     * @return
     */
    @GetMapping("/getAuthority")
    public ResultVO getAuthority(){
        return cmsAuthorityService.getAuthority();
    }
}
